<template>
	<view class="food-content">
		<view class="condition-block">
			<view class="condition-item">
				<picker @change="bindOrder" class="picker" :range="order" range-key="value">{{order[orderIndex].value}}</picker>
				<view class="iconfont icon-below-s"></view>
			</view>
			<view class="condition-item">
				<picker @change="bindType" class="picker" :range="type" range-key="value">{{type[typeIndex].value}}</picker>
				<view class="iconfont icon-below-s"></view>
			</view>
		</view>
		<view class="list-block">
			<block v-if="list.length>0">
			<navigator hover-class="none" :url="'/pages/common/detail?id='+item.id+'&category='+category" v-for="(item,index) in list" :key="item.id" class="list-item" v-if="item.files[0]">
				<view class="cover-block">
						<image :src="item.files[0].url" mode="widthFix" class="list-cover"></image>
						<view class="ranking-block">Top{{index+1}}</view>
					</view>
					<view class="info-block">
						<view class="name-block">
							<view class="name">{{item.name}}</view>
							<view class="iconfont icon-shoucang"></view>
							<view class="score">{{item.score}}</view>
						</view>
						<view class="introduce">{{item.description}}</view>
						<view class="label-block">
							<view v-for="(item1,index1) in item.type" class="label-item">{{item1}}</view>
						</view>
				</view>
			</navigator>
			</block>
			<view v-else class="empty">暂无数据</view>
		</view>
	</view>
</template>

<script>
	import {getList, getType} from '@/api/comprehensive.js';
	export default{
		data(){
			return{
				order:[
					{id:1,value:'默认排序'},
					{id:2,value:'评分最高'},
				],
				orderIndex:0,
				type:[
				],
				typeIndex:0,
				list:[
					
				],
				category:null,
			}
		},
		methods:{
			bindOrder(e){
				this.orderIndex=e.detail.value;
				this.getListData();
			},
			bindType(e){
				this.typeIndex=e.detail.value;
				this.getListData();
			},
			getTypeData(){
				uni.showLoading({
					title:'加载中',
					mask:true
				})
				getType({type:this.category}).then((res)=>{
					uni.hideLoading();
					if(res.status==1){
						this.type=res.data;
						this.getListData();
					}else{
						this.utils.showToast(res.message,()=>{
							uni.navigateBack()
						})
					}
				}).catch((res)=>{
					uni.hideLoading()
					this.utils.showToast('加载失败，请重试')
				})
			},
			getListData(){
				const order=this.order[this.orderIndex].id==1?'order asc':'score desc';
				uni.showLoading({
					title:'加载中',
					mask:true
				})
				getList({pageNum:1,pageSize:1000,type:this.type[this.typeIndex].id,order,category:this.category,}).then((res)=>{
					uni.hideLoading();
					if(res.status==1){
						this.list=res.data;
					}else{
						this.utils.showToast(res.message,()=>{
							uni.navigateBack()
						})
					}
				}).catch((res)=>{
					uni.hideLoading()
					this.utils.showToast('加载失败，请重试')
				})
			}
		},
		onLoad(e) {
			this.category=e.category;
			let title='';
			switch(e.category){
				case '1':
					title='吃在果园';
					break;
				case '2':
					title='玩在果园';
					break;
			}
			uni.setNavigationBarTitle({
				title:title
			})
			this.getTypeData();
		}
	}
</script>

<style lang="scss" scoped>
	.food-content{
		display: flex;
		width: 100%;
		flex-direction: column;
		padding: 30rpx;
		.condition-block{
			display: flex;
			flex-direction: row;
			margin-bottom: 30rpx;
			.condition-item{
				display: flex;
				flex-direction: row;
				align-items: center;
				height: 40rpx;
				margin-right: 60rpx;
				.picker{
					height: 100%;
					margin-right: 20rpx;
					font-weight: bold;
					font-size: 30rpx;
				}
				.iconfont{
					font-size: 24rpx;
				}
			}
		}
		.list-block{
			width: 100%;
			display: flex;
			flex-direction: column;
			.list-item{
				width: 100%;
				display: flex;
				flex-direction: column;
				margin-bottom: 20rpx;
				.cover-block{
					width: 100%;
					position: relative;
					.list-cover{
						width: 100%;
						border-radius: 30rpx;
					}
					.ranking-block{
						display: flex;
						padding: 6rpx 0 0 16rpx;
						color: #fff;
						position: absolute;
						font-size: 28rpx;
						top: 0;
						left: -2px;
						width: 120rpx;
						height: 60rpx;
						background: url('@/static/food/ranking.png') no-repeat center;
						background-size: 100% 100%;
					}
				}
				.info-block{
					display: flex;
					flex-direction: column;
					.name-block{
						display: flex;
						flex-direction: row;
						align-items: center;
						.name{
							font-size: 36rpx;
							font-weight: bold;
							margin-right: 30rpx;
						}
						.iconfont{
							color: #FD8249;
							font-size: 28rpx;
							margin-right: 10rpx;
						}
						.score{
							font-size: 26rpx;
							font-weight: bold;
						}
					}
					.introduce{
						margin-top: 20rpx;
						font-size: 26rpx;
						color: #999;
						overflow: hidden;
						text-overflow:ellipsis;
						white-space: nowrap;
					}
					.label-block{
						display: flex;
						flex-direction: row;
						flex-wrap: wrap;
						margin-top: 20rpx;
						.label-item{
							background: #DDFDFE;
							color: $uni-color-primary;
							font-size: 24rpx;
							padding: 5rpx 10rpx;
							margin-bottom: 16rpx;
							margin-right: 16rpx;
							border-radius: 12rpx;
						}
					}
				}
			}
		}
	}
</style>